package com.yuyou.fn.controller;


import com.alibaba.fastjson.JSONObject;
import com.github.wens.mybatisplus.plugins.Page;
import com.github.wens.mybatisplus.toolkit.IdWorker;
import com.google.common.collect.Collections2;
import com.yuyou.fn.common.exception.BusException;
import com.yuyou.fn.common.service.ISmsService;
import com.yuyou.fn.common.util.*;
import com.yuyou.fn.educational.entity.*;
import com.yuyou.fn.educational.service.*;
import com.yuyou.fn.educational.vo.*;
import com.yuyou.fn.platform.entity.CustomerUser;
import com.yuyou.fn.platform.service.IAccessTokenService;
import com.yuyou.fn.platform.service.ICaptchaService;
import com.yuyou.fn.platform.service.IOauthService;
import com.yuyou.fn.platform.vo.AccessTokenVo;
import com.yuyou.fn.portal.entity.*;
import com.yuyou.fn.portal.service.*;
import com.yuyou.fn.portal.vo.*;
import com.yuyou.fn.settlement.entity.AccountRecharge;
import com.yuyou.fn.settlement.entity.MainAccount;
import com.yuyou.fn.settlement.service.IAccountRechargeService;
import com.yuyou.fn.settlement.service.IMainAccountService;
import com.yuyou.fn.vo.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutionException;


/**
 * Created by wens on 16/10/24.
 */

@Controller
@RequestMapping(value="/api/m")
public class MApiController {

    @Resource
    private ICustomerUserService customerUserService ;


    @Resource
    private IOuterFeedbackService outerFeedbackService;

    @Resource
    private IOuterOrderService outerOrderService;

    @Resource
    private IOuterShoppingcartService outerShoppingcartService;

    @Resource
    private IOuterCollectionService outerCollectionService;


    @Resource
    private ITeacherService teacherService;

    @Resource
    private IAccessTokenService accessTokenService ;

    @Resource
    private ICustomerBindStudentService customerBindStudentService;

    @Resource
    private IOuterCourseClassService outerCourseClassService;

    @Resource
    private IOuterCampusService outerCampusService;


    @Resource
    private IOuterTeacherService outerTeacherService;

    @Resource
    private IStudentService studentService ;

    @Resource
    private IStudentRegService studentRegService ;

    @Resource
    private ICourseClassService courseClassService ;

    @Resource
    private IClassLectureService classLectureService ;

    @Resource
    private IAttendClassRecordService attendClassRecordService ;

    @Resource
    private RedisTemplate redisTemplate ;


    @Resource
    private IBaseGradeService baseGradeService;

    @Resource
    private ISmsService smsService;

    @Resource
    private IBaseSubjectService baseSubjectService;

    @Resource
    private IConfigService configService;

    @Resource
    private ICampusService campusService;

    @Resource
    private ICaptchaService captchaService;


    @Resource
    private IStudentSchoolService studentSchoolService;

    @Resource
    private IOnlineTestService onlineTestService ;

    @Resource
    private IOnlineTestResultService onlineTestResultService;

    @Resource
    private IMeasurementService measurementService;

    @Resource
    private ISuggestionService suggestionService;

    @Resource
    private IShiftClassRecordService shiftClassRecordService;

    @Resource
    private ICourseOrderDiscountService  courseOrderDiscountService ;

    @Resource
    private IDiscountQueryService discountService;


    @Resource
    private IAccountRechargeService accountRechargeService;

    @Resource
    private IClassExpandDetailService classExpandDetailService;

    @Resource
    private IDegreeSubscribeService degreeSubscribeService;

    @Resource
    private IMainAccountService mainAccountService;


    @Resource
    private IOauthService oauthService;

    @Resource
    private IRegRuleService regRuleService;

    @ApiOperation("根据集团通行证登录")
    @RequestMapping(value = "/loginByUC" , method = {RequestMethod.GET,RequestMethod.POST } )
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> ppIdLogin( @RequestParam("ticket") String ticket ) {
        CustomerUser customerUser = customerUserService.loginFormUC(ticket);
        if(customerUser == null ){
            return ReturnResult.success();
        }
        String token = accessTokenService.generateToken(customerUser.getUserId(),customerUser.getUsername(),"customerUser" );
        return ReturnResult.success(new CustomerUserLoginSuccessVo(token,customerUser));
    }



    @ApiOperation("微信登录")
    @RequestMapping(value = "/wx/login" , method = {RequestMethod.GET,RequestMethod.POST } )
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> wxLogin( @RequestParam("openId") String openId , @RequestParam(value = "nickname" , required = false ) String nickname ,@RequestParam(value = "sex" , required = false ) String sex , @RequestParam(value = "province" , required = false) String province ,@RequestParam(value = "city",required = false) String city  ,@RequestParam(value = "avatar",required = false) String avatar ) {
        CustomerUser customerUser = customerUserService.loginFormWx(openId, nickname, sex, province, city, avatar);
        if(customerUser == null ){
            return ReturnResult.success();
        }
        String token = accessTokenService.generateToken(customerUser.getUserId(),customerUser.getUsername(),"customerUser" );
        return ReturnResult.success(new CustomerUserLoginSuccessVo(token,customerUser));
    }

    @ApiOperation("微信解绑")
    @RequestMapping(value = "/wx/unbindPhoneNo" , method = {RequestMethod.GET,RequestMethod.POST } )
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> wxUnbindPhoneNo( @RequestParam("openId") String openId  ) {
        oauthService.unbind(openId,1);
        return ReturnResult.success("ok");
    }


    @ApiOperation("微信绑定手机号码")
    @RequestMapping(value = "/wx/bindPhoneNo" , method = {RequestMethod.GET,RequestMethod.POST } )
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> wxBindPhoneNo(@RequestParam("phoneNo") String phoneNo,@RequestParam(value = "code" ) String code, @RequestParam("openId") String openId , @RequestParam(value = "nickname" , required = false ) String nickname ,@RequestParam(value = "sex" , required = false ) String sex , @RequestParam(value = "province" , required = false) String province ,@RequestParam(value = "city",required = false) String city  ,@RequestParam(value = "avatar",required = false) String avatar ) {

        if( !smsService.validate(phoneNo, code) ){
            captchaService.opsStat(phoneNo, "login");
            throw new BusException("手机验证码不正确");
        }

        CustomerUser customerUser = customerUserService.wxBindPhoneNo(phoneNo,openId, nickname, sex, province, city, avatar);
        String token = accessTokenService.generateToken(customerUser.getUserId(),customerUser.getUsername(),"customerUser" );
        return ReturnResult.success(new CustomerUserLoginSuccessVo(token,customerUser));
    }

    @ApiOperation("手机登陆")
    @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> login(@ApiParam(value = "手机号码") @RequestParam(value = "phoneNo") String phoneNo ,
                                                          @ApiParam(value = "短信验证码") @RequestParam(value = "code" ) String code) {


        if( !smsService.validate(phoneNo, code) ){
            captchaService.opsStat(phoneNo, "login");
            throw new BusException("手机验证码不正确");
        }

        CustomerUser customerUser  = customerUserService.createCustomerUserIfNeed(phoneNo,null , null );
        String accessToken = accessTokenService.generateToken(customerUser.getUserId(),customerUser.getUsername(),"customerUser" );
        return  ReturnResult.success(new CustomerUserLoginSuccessVo(accessToken, customerUser));
    }




    @ApiOperation("自动登录")
    @RequestMapping(value = "/autoLogin" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> autoLogin(@ApiParam(value = "accessToken") @RequestParam(value = "accessToken") String accessToken) throws IOException {

        // 自动登录
        AccessTokenVo accessTokenVo = accessTokenService.validAccessToken(accessToken);
        CustomerUser customerUser = customerUserService.findById(accessTokenVo.getUserId());
        if(null == customerUser){
            return ReturnResult.fail("无法找到对应的用户信息");
        }
        return  ReturnResult.success(new CustomerUserLoginSuccessVo(accessToken, customerUser));
    }


    @ApiOperation(value = "生成图片验证码" )
    @RequestMapping(value = "/generatePictureCaptcha",method = { RequestMethod.GET ,RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Void> generatePictureCaptcha(HttpServletResponse response) throws IOException {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");

        captchaService.outputImage(100,40,response.getOutputStream());
        return ReturnResult.success("ok");
    }

    @ApiOperation("更改手机号码")
    @RequestMapping(value = "/u/changePhoneNo" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CustomerUserLoginSuccessVo> changePhoneNo(@ApiParam(value = "新号码", required = true) @RequestParam("newPhoneNo") String newPhoneNo,
                                                                  @ApiParam(value = "短信验证码", required = true) @RequestParam(value = "code" ) String code,
                                                                  HttpServletRequest request) throws IOException {
        if( !smsService.validate(newPhoneNo, code) ){
            throw new BusException("手机验证码不正确");
        }
        AccessTokenVo accessTokenVo = (AccessTokenVo)request.getAttribute("accessToken");
        Long userId = accessTokenVo.getUserId();
        CustomerUser customerUser = customerUserService.findById(userId);

        customerUser.setPhoneNo(newPhoneNo.trim());
        customerUser.setUpdateTime(TimeUtils.now());
        customerUserService.updateSelectiveById(customerUser);

        return  ReturnResult.success(new CustomerUserLoginSuccessVo(accessTokenVo.getToken(), customerUser));
    }






    @ApiOperation("查询课程列表")
    @RequestMapping(value = "/outCourseClassList" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<SimpleCourseClass>> outCourseClassList( @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, OuterCourseClassQueryVo outerCourseClassQueryVo, HttpServletRequest request) {
        String token=request.getHeader("accessToken")==null?request.getParameter("accessToken"):"";
        if (StringUtils.isNotEmpty(token)){
            AccessTokenVo accessToken = accessTokenService.validAccessToken(request.getParameter("accessToken"));
            Long userId=accessToken.getUserId();
            String lastCampusGeoLocation=configService.findConfigCampusGeoLocation(userId);
            if (StringUtils.isNotEmpty(lastCampusGeoLocation)){
                String[] array=lastCampusGeoLocation.split(" ");
                outerCourseClassQueryVo.setLatitude(Double.parseDouble(array[1]));
                outerCourseClassQueryVo.setLongitude(Double.parseDouble(array[0]));
            }
        }

        List<SimpleCourseClass> outerCourseClasses=outerCourseClassService.findOuterCourseClassByCondition(outerCourseClassQueryVo,pageNo,pageSize);
        return ReturnResult.success(outerCourseClasses);
    }

    @ApiOperation("根据课程id查询")
    @RequestMapping(value = "/outCourseClassesByIds" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,Object>> outCourseClassesByIds(@RequestParam("teacherId")Long teacherId,@RequestParam(value = "studentId",required = false)Long studentId,@RequestParam("classIds")String classIds, HttpServletRequest request) {
        Map<String,Object> map=new HashMap<>();
        Teacher teacher=teacherService.findById(teacherId,"teacherId","teacherName");
        if (studentId!=null){
            Student student=studentService.findById(studentId,"studentId","name");
            map.put("student",student);
        }

        List<SimpleCourseClass> outerCourseClasses=outerCourseClassService.findSimpleCourseClassByClassIds(Utils.toLongIds(classIds));
        map.put("teacher",teacher);
        map.put("outerCourseClasses",outerCourseClasses);
        return ReturnResult.success(map);
    }


    @ApiOperation("普通课程详情")
    @RequestMapping(value = "/outCourseClass" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CourseClassDetail> outCourseClass(@RequestParam(value = "classId",required = true) Long classId,
                                                          @RequestParam(value = "accessToken",required = false) String accessToken) {
        CourseClassDetail courseClassDetail=outerCourseClassService.findClassDetailByClassId(classId);//new CourseClassDetail();
        if(StringUtils.isNotEmpty(accessToken)){
            AccessTokenVo accessTokenVo = accessTokenService.validAccessToken(accessToken);
            Long userId=accessTokenVo.getUserId();
            //是否被收藏
            OuterCollection outerCollection =outerCollectionService.findByUserIdAndObjType(userId,classId,0);//0代表课程
            if (outerCollection != null && outerCollection.getOuterCollectionId() != null){
                courseClassDetail.setIsCollection(1L);
                courseClassDetail.setOuterCollectionId(outerCollection.getOuterCollectionId());
            }else{
                courseClassDetail.setIsCollection(0L);
                courseClassDetail.setOuterCollectionId(null);
            }
        }else{
            courseClassDetail.setIsCollection(0L);
        }
        return ReturnResult.success(courseClassDetail);
    }

    @ApiOperation("查询老师列表")
    @RequestMapping(value = "/teachers" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<TeacherListResultVo>> teachers(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, OuterTeacher outerTeacher, HttpServletRequest request) {

        if (StringUtils.isNotEmpty(outerTeacher.getTeacherName()) && StringUtils.isNotEmpty(outerTeacher.getCity())){
            redisTemplate.opsForZSet().incrementScore("teacher_search_"+outerTeacher.getCity(),outerTeacher.getTeacherName(),1);
        }


        List<OuterTeacher> outerTeacherList=outerTeacherService.findTeacherByCond(pageNo,pageSize,outerTeacher);
        List<TeacherListResultVo> teacherListResultVoList=new ArrayList<TeacherListResultVo>();
        for(OuterTeacher outerTeacher1:outerTeacherList){
            TeacherListResultVo teacherListResultVo=new TeacherListResultVo();
            BeanUtils.copyProperties(teacherListResultVo,outerTeacher1);
            teacherListResultVoList.add(teacherListResultVo);
        }
        //page.setRecords(teacherListResultVoList);
        return ReturnResult.success(teacherListResultVoList);
    }

    @ApiOperation("老师主页(个人信息)")
    @RequestMapping(value = "/teacherDetail" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<TeacherListResultVo> teacherDetail(@RequestParam("teacherId") Long teacherId,
                                                           @RequestParam("accessToken") String accessToken) {

        Teacher teacher=teacherService.findById(teacherId);
        TeacherListResultVo teacherListResultVo=new TeacherListResultVo();

        if (teacher.getJobNature()!=null && teacher.getJobNature()==1){
            teacher.setTeacherName(StringUtils.isNotEmpty(teacher.getTeacherName())?teacher.getTeacherName().charAt(0)+"老师":"");
        }
        BeanUtils.copyProperties(teacherListResultVo,teacher);
        if(StringUtils.isNotEmpty(accessToken)){
            AccessTokenVo accessTokenVo = accessTokenService.validAccessToken(accessToken);
            Long userId = accessTokenVo.getUserId();
            OuterCollection outerCollection = outerCollectionService.findByUserIdAndObjType(userId,teacherId,1);//0代表老师
            if (outerCollection != null && outerCollection.getOuterCollectionId() != null){
                teacherListResultVo.setIsCollection(1L); //已收藏
                teacherListResultVo.setOuterCollectionId(outerCollection.getOuterCollectionId());
            }else{
                teacherListResultVo.setIsCollection(0L); //未收藏
                teacherListResultVo.setOuterCollectionId(null);
            }
        }else{
            teacherListResultVo.setIsCollection(0L); //未收藏，这里设置不为null,前端需要
        }

        return ReturnResult.success(teacherListResultVo);
    }

    @ApiOperation("查找老师课程")
    @RequestMapping(value = "/teacherClass" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<SimpleCourseClass>> teacherClass(@RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, @RequestParam("teacherId") Long teacherId, HttpServletRequest request) {
        OuterCourseClassQueryVo outerCourseClassQueryVo=new OuterCourseClassQueryVo();
        outerCourseClassQueryVo.setTeacherId(teacherId);
        List<SimpleCourseClass> outerCourseClassList=outerCourseClassService.findOuterCourseClassByCondition(outerCourseClassQueryVo,pageNo,pageSize);
        return ReturnResult.success(outerCourseClassList);
    }

    @ApiOperation("购物车列表")
    @RequestMapping(value = "/u/shoppingCartList" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<ShoppingCartDetailVo>> shoppingCartList(HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        List<ShoppingCartDetailVo> shoppingCartDetailVoList=outerShoppingcartService.findShoppingCartList(userId);
        return ReturnResult.success(shoppingCartDetailVoList);
    }

    @ApiOperation("订单确认列表")
    @RequestMapping(value = "/u/orderConfirmList" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<ShoppingCartDetailVo>> orderConfirmList(@RequestParam(value = "outerShoppingCartIds[]") List<Long> outerShoppingCartIds,HttpServletRequest request) {
        List<ShoppingCartDetailVo> shoppingCartDetailVoList=outerShoppingcartService.findShoppingCartList(outerShoppingCartIds);
        return ReturnResult.success(shoppingCartDetailVoList);
    }


    @ApiOperation("计算优惠")
    @RequestMapping(value = "/u/calDiscount" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<ShoppingCartDetailVo>> calDiscount(@RequestParam(value = "outerShoppingCartIds[]") List<Long> outerShoppingCartIds,@RequestParam("studentId") Long studentId,HttpServletRequest request) {
        return ReturnResult.success(outerOrderService.calDiscountFromShoppingCart(outerShoppingCartIds,studentId));
    }


    @ApiOperation("一键添加到购物车")
    @RequestMapping(value = "/u/addToShoppingCartByQrCode" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addToShoppingCartByQrCode(@RequestParam(value = "classIds") String classIds,@RequestParam(value = "counselorId",required = false)Long counselorId, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        outerShoppingcartService.addToShoppingCartByQrCode(Utils.toLongIds(classIds),userId ,counselorId);
        return ReturnResult.success("添加成功");
    }


    @ApiOperation("添加到购物车")
    @RequestMapping(value = "/u/addToShoppingCart" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addToShoppingCart(@RequestParam(value = "classId") Long classId,@RequestParam(value = "counselorId",required = false)Long counselorId, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        outerShoppingcartService.addToShoppingCart(classId,userId ,counselorId);
        return ReturnResult.success("添加成功");
    }

    @ApiOperation("删除购物车")
    @RequestMapping(value = "/u/deleteShoppingCart" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OuterShoppingcart> deleteShoppingCart(@RequestParam(value="outerShoppingCartIds[]") List<Long> outerShoppingCartIds, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        outerShoppingcartService.deleteShoppingCart(outerShoppingCartIds,userId);
        return ReturnResult.success("删除成功");
    }



    @ApiOperation("普通课程立即报名（选择学生后调用）")
    @RequestMapping(value = "/u/createOneOuterOrder" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Long> createOneOuterOrder(@RequestParam(value = "classId") Long classId,@RequestParam("studentId") Long studentId , @RequestParam(value = "counselorId",required = false)Long counselorId, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        Long outerOrderId = outerOrderService.createOuterOrder(classId, studentId, userId, counselorId);
        /*保存用户最新购买的校区*/
        Threads.dispatch(new Runnable() {
            @Override
            public void run() {
                outerOrderService.saveLastCampusGeoLocation(userId);
            }
        });
        return ReturnResult.success(outerOrderId);
    }


    @ApiOperation("取消订单")
    @RequestMapping(value = "/u/cancelOuterOrder" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OuterOrderDetail> cancelOuterOrder(@RequestParam(value = "chargingStatus",defaultValue = "4") Integer chargingStatus, @RequestParam(value = "outerOrderId") Long outerOrderId, HttpServletRequest request) {
        outerOrderService.cancelOuterOrder(outerOrderId,chargingStatus);
        return ReturnResult.success("ok");
    }


    @ApiOperation("购物车结算")
    @RequestMapping(value = "/u/createOuterOrders" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Long> createOuterOrders(@RequestParam(value = "outerShoppingCartIds[]") List<Long> outerShoppingCartIds ,@RequestParam("studentId") Long studentId, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        Long outerOrderId = outerOrderService.createOuterOrderFromShoppingCart(outerShoppingCartIds, studentId, userId);
               /*保存用户最新购买的校区*/
        Threads.dispatch(new Runnable() {
            @Override
            public void run() {
                outerOrderService.saveLastCampusGeoLocation(userId);
            }
        });
        return ReturnResult.success(outerOrderId);
    }


    @ApiOperation("得到订单列表")
    @RequestMapping(value = "/u/findOuterOrder" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OuterOrderDetail>> findOuterOrder(@RequestParam(value = "chargingStatusStr",defaultValue = "0,1",required = false) String chargingStatusStr, @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        String[] chargingStatusArr=chargingStatusStr.split(",");
        List<Integer> chargingStatusList=new ArrayList<>(chargingStatusArr.length);
        for (String chargingStatus:chargingStatusArr){
            chargingStatusList.add(Integer.parseInt(chargingStatus));
        }
        List<OuterOrderDetail> list=outerOrderService.findOuterOrder(userId,pageNo,pageSize,chargingStatusList).getRecords();
        return ReturnResult.success(list);
    }

    @ApiOperation("根据订单id查询订单")
    @RequestMapping(value = {"/findOneOuterOrder" ,"/u/findOneOuterOrder"} , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public  ReturnResult<OuterOrderDetail> findOuterOrder(@RequestParam("outerOrderId") Long outerOrderId, HttpServletRequest request) {
        OuterOrderDetail orderCourseClass=outerOrderService.findOuterOrder(outerOrderId);
        return ReturnResult.success(orderCourseClass);
    }

    @ApiOperation("根据订单id查询订单")
    @RequestMapping(value = "/checkOrderCourseStatus" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public  ReturnResult<OuterOrderDetail> checkOrderCourseStatus(@RequestParam("outerOrderId") Long outerOrderId, HttpServletRequest request) {
        OuterOrder outerOrder = outerOrderService.findById(outerOrderId, "chargingStatus");
        return ReturnResult.success(outerOrder.getChargingStatus());
    }


    @ApiOperation("添加收藏")
    @RequestMapping(value = "/u/addOuterCollection" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Long> addOuterCollection(OuterCollection outerCollection, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        Long outerConllectionId=outerCollectionService.addOuterCollection(outerCollection,userId);
        return ReturnResult.success(outerConllectionId);
    }


    @ApiOperation("得到年级列表")
    @RequestMapping(value = "/gradeList" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<BaseGrade>> gradeList(HttpServletRequest request) {
        List<BaseGrade> baseGradeList=baseGradeService.findAllFromCache();
        return ReturnResult.success(baseGradeList);
    }


    @ApiOperation("得到年级和科目列表")
    @RequestMapping(value = "/gradeAndSubjectList" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Object> gradeAndSubjectList(HttpServletRequest request) {
        List<BaseGrade> baseGradeList=baseGradeService.findAllFromCache();
        List<BaseSubject> baseSubjectList=baseSubjectService.findAllFromCache();
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("baseGradeList",baseGradeList);
        map.put("baseSubjectList",baseSubjectList);
        return ReturnResult.success(map);
    }

    @ApiOperation("删除收藏")
    @RequestMapping(value = "/u/deleteOuterCollection", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OuterCollection> deleteOuterCollection(@RequestParam(value="outerCollectionIds[]") List<Long> outerCollectionIds, HttpServletRequest request) {

        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();

        outerCollectionService.deleteOuterCollection(userId,outerCollectionIds);
        return ReturnResult.success("删除成功");
    }

    @ApiOperation("得到收藏列表")
    @RequestMapping(value = "/u/findOuterCollection", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Object>> findOuterCollection(@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize, HttpServletRequest request) {

        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();

        List<Object> list=outerCollectionService.findOuterCollection(pageNo,pageSize,userId);

        return ReturnResult.success(list);
    }


    @ApiOperation("新增学员")
    @RequestMapping(value = "/u/addNewStudentAndBind", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> addNewStudentAndBind(@RequestParam(value="code") String code ,@RequestParam("name") String name, @RequestParam("phoneNo") String phoneNo, @RequestParam("sex") Integer sex, @RequestParam("gradeId") Long gradeId,HttpServletRequest request ) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        boolean validate = smsService.validate(phoneNo, code);
        if(!validate){
            throw new BusException("短信验证码不正确");
        }

        Student student = studentService.findByNameAndPhone(name, phoneNo);

        StudentSaveOrUpdateVo studentSaveOrUpdateVo = new StudentSaveOrUpdateVo();
        studentSaveOrUpdateVo.setName(name);
        studentSaveOrUpdateVo.setPhoneNo(phoneNo);
        studentSaveOrUpdateVo.setSex(sex);
        studentSaveOrUpdateVo.setGradeId(gradeId);

        if(student != null ){
            studentSaveOrUpdateVo.setStudentId(student.getStudentId());
        }
        Long studentId = studentService.saveOrUpdateStudent(studentSaveOrUpdateVo);
        customerBindStudentService.insertByStudentId(studentId,userId);
        return ReturnResult.success("添加成功");
    }



    @ApiOperation("解绑学员")
    @RequestMapping(value = "/u/solutionStudent", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<HashMap<String,String>> solutionStudent(@RequestParam(value="studentId") Long studentId,HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        customerBindStudentService.deleteByStudentIdAndUserId(studentId,userId);
        return ReturnResult.success("解绑成功");
    }


    @ApiOperation("自动绑定学员")
    @RequestMapping(value = "/u/autoBindStudent", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<HashMap<String,String>> autoBindStudent(@RequestParam(value="studentId") Long studentId,HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        customerBindStudentService.insertByStudentId(studentId,userId);
        return ReturnResult.success("绑定成功");
    }


    @ApiOperation("我的课程")
    @RequestMapping(value = "/u/findOuterCourseClass", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<StudentCourseClass>> findOuterCourseClass(@RequestParam(value = "studentId",required = true) Long studentId, @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, @RequestParam(value = "chargingStatus",defaultValue = "2") int chargingStatus, @RequestParam(value = "regStatus",defaultValue = "0") int regStatus, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        List<StudentCourseClass> list=outerOrderService.findStudentCourseClass(userId,studentId,pageNo,pageSize,regStatus);
        return ReturnResult.success(list);
    }


    @ApiOperation("更改个人信息")
    @RequestMapping(value = "/u/updatePersonMessage",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CustomerUser> updatePersonMessage( CustomerUser customerUser, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        customerUser.setUserId(userId);
        customerUserService.updatePersonMessage(customerUser);
        return ReturnResult.success("ok");
    }




    @ApiOperation("得到用户绑定的学员")
    @RequestMapping(value = "/u/findCustomerBindStudent" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CustomerBindStudentVo>> findCustomerBindStudent(HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        return  ReturnResult.success(customerBindStudentService.findStudentsByUserIds(userId));
    }

    @ApiOperation("获取绑定的学员详情")
    @RequestMapping(value = "/u/findBindStudentDetail" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CustomerBindStudentVo> findBindStudentDetail(@RequestParam("studentId") Long studentId) {
        return  ReturnResult.success(customerBindStudentService.findBindStudentDetail(studentId));
    }

    @ApiOperation("更新绑定的学员信息")
    @RequestMapping(value = "/u/updateBindStudentInfo" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> updateBindStudentInfo(@RequestParam("studentId")Long studentId ,@RequestParam(value = "gradeId",required = false) Long gradeId,@RequestParam(value = "school",required = false) String school , @RequestParam(value = "location",required = false) String location , @RequestParam(value = "address",required = false) String address) {
        customerBindStudentService.updateBindStudentInfo( studentId , gradeId, school ,  location ,  address);
        return  ReturnResult.success("OK");
    }


    @ApiOperation("联系我们")
    @RequestMapping(value = "/u/contactUs",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> contactUs(OuterFeedback outerFeedback, HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        outerFeedback.setUserId(userId);
        outerFeedbackService.contactUs(outerFeedback);
        return ReturnResult.success("ok");
    }


    @ApiOperation("根据经纬度搜索附近校区")
    @RequestMapping(value = "/findCampusByPosition" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OuterCampus>> findCampusByPosition(@RequestParam(value = "distance",required = false,defaultValue = "100000") Double distance,@RequestParam(value = "longitude") Double longitude,@RequestParam(value = "latitude") Double latitude, HttpServletRequest request) {
        List<OuterCampus> outerCampuses = outerCampusService.findCampusByPosition(distance, longitude, latitude);

        Collection<OuterCampusVo> ret = Collections2.transform(outerCampuses,(input)->{
            OuterCampusVo outerCampusVo = new OuterCampusVo() ;
            BeanUtils.copyProperties(outerCampusVo,input);
            outerCampusVo.setDistance(DistanceUtils.getDistance(latitude,longitude,input.getCampusLocation().getY(),input.getCampusLocation().getX() ));
            return outerCampusVo;
        });

        return ReturnResult.success(ret);
    }

    @ApiOperation("查询区域校区")
    @RequestMapping(value = "/findCampusByAreaTeamId" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Campus>> findCampusByAreaTeamId(@RequestParam(value = "areaTeamId") Long  areaTeamId,@RequestParam(value = "longitude") Double longitude,@RequestParam(value = "latitude") Double latitude, HttpServletRequest request) {
        List<Campus> campusList=campusService.findCampusByAreaTeamIdState(areaTeamId,1);

        Collection<OuterCampusVo> ret = Collections2.transform(campusList,(input)->{
            OuterCampusVo outerCampusVo = new OuterCampusVo() ;
            BeanUtils.copyProperties(outerCampusVo,input);
            String[] geoLocation=input.getGeoLocation()==null?new String[]{"0","0"}:input.getGeoLocation().split(" ");
            double latitude1=geoLocation[1]==null?0d:Double.parseDouble(geoLocation[1]);
            double longitude1=geoLocation[0]==null?0d:Double.parseDouble(geoLocation[0]);
            outerCampusVo.setDistance(DistanceUtils.getDistance(latitude,longitude,latitude1,longitude1 ));
            return outerCampusVo;
        });
        List<OuterCampusVo> outerCampusVoList=new ArrayList<>(ret);
        Collections.sort(outerCampusVoList, new Comparator<OuterCampusVo>() {
            @Override
            public int compare(OuterCampusVo o1, OuterCampusVo o2) {
                return o1.getDistance()<=o2.getDistance()?-1:1;
            }
        });

        return ReturnResult.success(outerCampusVoList);
    }



    @ApiOperation("查询个人信息")
    @RequestMapping(value = "/u/personMessage",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<PersonMessageVo> personMessage(  HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        CustomerUser customerUser=customerUserService.findById(userId);
        if (customerUser==null){
            return ReturnResult.fail("查询不到个人信息");
        }
        PersonMessageVo personMessageVo=new PersonMessageVo();
        BeanUtils.copyProperties(personMessageVo,customerUser);
        personMessageVo.setShoppingCartNum(outerShoppingcartService.countNumByUserId(userId));
        personMessageVo.setCollectionNum(outerCollectionService.countNumByUserId(userId));
        Integer[] chargingStatusArr={0,1};
        personMessageVo.setUnFinishOrderNum(outerOrderService.countOuterOrder(userId,Arrays.asList(chargingStatusArr)));
        return ReturnResult.success(personMessageVo);
    }


    @ApiOperation("购物车数量")
    @RequestMapping(value = "/u/cartNum",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Integer> cartNum(  HttpServletRequest request) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();

        return ReturnResult.success( outerShoppingcartService.countNumByUserId(userId).intValue());
    }



    @ApiOperation("我的课表")
    @RequestMapping(value = "/u/schedule" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ScheduleInfoVo>> schedule(@RequestParam(value = "studentId",required = false) Long studentId,@RequestParam(value = "dateString",required = true) String  dateString, HttpServletRequest request) {

        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        List<ScheduleInfoVo> scheduleInfoVoList=outerCourseClassService.findScheduleInfoByUserIdAndDate(studentId,userId,dateString);

        return ReturnResult.success(scheduleInfoVoList);
    }

    @ApiOperation("根据地名得到经纬度")
    @RequestMapping(value = "/lngAndLatByPositionName" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,Double>> lngAndLatByPositionName(@RequestParam(value = "positonName",required = true) String positionName, HttpServletRequest request) {
        // HashMap<String,Object> resultMap=configurationTableService.findConfigByCond(configurationTable);
        Map<String,Double> map= MapBaidu.findLngAndLat(positionName);

        return ReturnResult.success(map);
    }


    @ApiOperation("根据经纬度得到地名")
    @RequestMapping(value = "/positionNameByLngAndLat" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<JSONObject> positionNameByLngAndLat(@RequestParam(value = "lng",required = true) Double lng, @RequestParam(value = "lat",required = true) Double lat, HttpServletRequest request) {
        // HashMap<String,Object> resultMap=configurationTableService.findConfigByCond(configurationTable);
        JSONObject jsonObject=MapBaidu.findPositionByLngAndLat(lng,lat);// MapBaidu.getLngAndLat(positionName);

        return ReturnResult.success(jsonObject);
    }

    @ApiOperation("得到校区搜索条件")
    @RequestMapping(value = "/findCampusCond" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CampusCondVo>> findCampusCond(@RequestParam(value = "city",required = true,defaultValue = "广州") String  city,HttpServletRequest request) {
        List<CampusCondVo> campusCondVoList=campusService.findCampusCond(city);
        return ReturnResult.success(campusCondVoList);
    }


    @ApiOperation("考勤课程")
    @RequestMapping(value = "/attendanceCourseClass" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<AttendanceCourseClassForStudentVo> > attendanceCourseClass(@RequestParam("studentId") final Long studentId , HttpServletRequest request) throws InterruptedException, ExecutionException {

        /*List<StudentReg> studentRegList = studentRegService.findStudentRegByStudentId(studentId , DateUtils.addYears(TimeUtils.now(), -1 ));
        List<Long> classIds  = BeanUtils.toList(studentRegList,"classId");
        List<CourseClass> courseClassList = courseClassService.findByIds(classIds);

        List<Callable<AttendanceCourseClassForStudentVo>> taskList  = new ArrayList<>(courseClassList.size());

        for(final CourseClass courseClass : courseClassList ){

            taskList.add(new Callable<AttendanceCourseClassForStudentVo>() {
                @Override
                public AttendanceCourseClassForStudentVo call() throws Exception {

                    AttendanceCourseClassForStudentVo attendanceCourseClassForStudentVo = new AttendanceCourseClassForStudentVo();
                    attendanceCourseClassForStudentVo.setCourseClass(courseClass);
                    List<ClassLecture> classLectureList = classLectureService.findHahAttendanceClassLectureByClassId(courseClass.getClassId());
                    if(classLectureList.isEmpty() ){
                        return attendanceCourseClassForStudentVo ;
                    }

                    List<Long> classLectureIds = BeanUtils.toList(classLectureList,"classLectureId");
                    List<AttendClassRecord> attendClassRecordList = attendClassRecordService.findByRegIdClassLectureIds(regId, classLectureIds);

                    for(AttendClassRecord attendClassRecord : attendClassRecordList ){
                        if(attendClassRecord.getAttendanceStatus() == 0 ){
                            attendanceCourseClassForStudentVo.setAttendanceTime(attendanceCourseClassForStudentVo.getAttendanceTime() + 1 );
                        }else if(attendClassRecord.getAttendanceStatus() == 1 ){
                            attendanceCourseClassForStudentVo.setAbsenceTime(attendanceCourseClassForStudentVo.getAbsenceTime() +  1);
                        }else if(attendClassRecord.getAttendanceStatus() == 2){
                            attendanceCourseClassForStudentVo.setLateTime(attendanceCourseClassForStudentVo.getLateTime() + 1 );
                        }else if(attendClassRecord.getAttendanceStatus() == 3 ){
                            attendanceCourseClassForStudentVo.setLeaveTime(attendanceCourseClassForStudentVo.getLeaveTime() + 1 );
                        }
                    }
                    return attendanceCourseClassForStudentVo;
                }
            });
        }

        List<Future<AttendanceCourseClassForStudentVo>> futures = Threads.invokeAll(taskList);
        List<AttendanceCourseClassForStudentVo> retList = new ArrayList<>(futures.size());
        for(Future<AttendanceCourseClassForStudentVo> f : futures ){
            retList.add(f.get());
        }

        return ReturnResult.success(retList);*/

        /** todo */
        return null ;
    }

    @ApiOperation("每讲考勤详情列表")
    @RequestMapping(value = "/attendanceDetailListOfLecture" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<AttendClassRecordDetailVo>> attendanceDetailListOfLecture(@RequestParam("classId") Long classId , @RequestParam("regId") Long regId , HttpServletRequest request) {

        List<ClassLecture> classLectureList = classLectureService.findHahAttendanceClassLectureByClassId(classId);
        List<Long> classLectureIds = BeanUtils.toList(classLectureList,"classLectureId");
        List<AttendClassRecord> attendClassRecordList = attendClassRecordService.findByRegIdClassLectureIds(regId, classLectureIds);

        Map<Long,AttendClassRecord> attendClassRecordMap = BeanUtils.toMap(attendClassRecordList,"classLectureId");
        List<AttendClassRecordDetailVo> retList  = new ArrayList<>(classLectureList.size());

        for(ClassLecture classLecture : classLectureList ){
            AttendClassRecord attendClassRecord = attendClassRecordMap.get(classLecture.getClassLectureId());
            AttendClassRecordDetailVo attendanceRecordDetailForStudentVo = new AttendClassRecordDetailVo();
            BeanUtils.copyProperties(attendanceRecordDetailForStudentVo,attendClassRecord);
            attendanceRecordDetailForStudentVo.setClassLecture(classLecture);
            retList.add(attendanceRecordDetailForStudentVo);
        }

        return ReturnResult.success(retList);
    }




    @ApiOperation("众筹名师")
    @RequestMapping(value = "/raiseTeacher" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OuterTeacher>> raiseTeacher(@RequestParam(value = "gradeId",required = false) String gradeId,@RequestParam(value = "subjectId",required = false) String subjectId,
                                                         @RequestParam(value = "city",required = false) String city,
            @RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize,HttpServletRequest request) throws InterruptedException, ExecutionException {
        OuterTeacher outerTeacher=new OuterTeacher();
        outerTeacher.setTeachGradeIds(gradeId);
        outerTeacher.setTeachSubjectIds(subjectId);
        outerTeacher.setCity(city);
        outerTeacher.setJobNature("0");
        List<OuterTeacher> outerTeacherList=outerTeacherService.findTeacherByCond(pageNo,pageSize,outerTeacher);
        return ReturnResult.success(outerTeacherList);
    }



    @ApiOperation("推荐续读课程")
    @RequestMapping(value = "/suggestContinueClass" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<SuggestResultVo> suggestContinueClass(@RequestParam("studentId") Long studentId){
        SuggestResultVo suggestResultVo = suggestionService.suggestContinueClass(studentId);
        return ReturnResult.success(suggestResultVo) ;

    }


    @ApiOperation("根据地区查找生源学校")
    @RequestMapping(value = "/searchSchool" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<StudentSchool>> searchSchool(@RequestParam("province") String province ,@RequestParam("city") String city ,@RequestParam(value = "district") String district , @RequestParam(value = "query" , required = false) String query  ){
        List<StudentSchool> list  = studentSchoolService.searchStudentSchool(province , city, district,query );
        return ReturnResult.success(list) ;

    }


    @ApiOperation("测评列表")
    @RequestMapping(value = "/onlineTestList" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OnlineTestVo>> onlineTestList(@RequestParam("studentId") Long studentId ){
        List<OnlineTest> onlineTests = onlineTestService.findOnlineTestForTests(studentId);
        List<Long> onlineTestIds  = BeanUtils.toList(onlineTests,"onlineTestId");
        List<OnlineTestResult> results = onlineTestService.findOnlineTestResults(onlineTestIds);
        Map<Long,List<OnlineTestResult>> onlineTestId2OnlineTestResult =  BeanUtils.toGroup(results,"onlineTestId");
        List<OnlineTestVo> vos = new ArrayList<>(onlineTests.size());
        for(OnlineTest onlineTest : onlineTests ){
            vos.add( new OnlineTestVo(onlineTest,onlineTestId2OnlineTestResult.get(onlineTest.getOnlineTestId())) );
        }

        return ReturnResult.success(vos) ;
    }

    @ApiOperation("写入外部测评成绩")
    @RequestMapping(value = "/saveExternalScore" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OnlineTestVo>> saveExternalScore(@RequestParam("onlineTestId") Long onlineTestId , @RequestParam("score") Double score ){
        onlineTestService.saveExternalScore(onlineTestId,score);
        return ReturnResult.success("OK") ;
    }



    @ApiOperation("开始做卷")
    @RequestMapping(value = "/beginTesting" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OnlineTestResult> beginTesting(@RequestParam("onlineTestId") Long onlineTestId ){
        OnlineTestResult onlineTestResult = onlineTestService.beginTesting(onlineTestId);
        return ReturnResult.success(onlineTestResult) ;
    }

    @ApiOperation("保存做题结果")
    @RequestMapping(value = "/saveTestResult" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveTestResult(@RequestParam("onlineTestResultId") Long onlineTestResultId , @RequestParam("testDuration") Integer testDuration , @RequestParam("answerDetail") String  answerDetail , @RequestParam("isComplete") Boolean isComplete ){
        onlineTestService.saveTestResult(onlineTestResultId , testDuration , answerDetail ,isComplete ) ;
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("获取测试结果")
    @RequestMapping(value = "/onlineTestResult" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OnlineTestResultVo> onlineTestResult(@RequestParam("onlineTestResultId") Long onlineTestResultId){
        OnlineTestResult onlineTestResult = onlineTestResultService.findById(onlineTestResultId, "onlineTestId", "score");
        OnlineTest onlineTest = onlineTestService.findById(onlineTestResult.getOnlineTestId());
        List<Measurement> measurements = measurementService.findReachMeasurementForScore(onlineTest.getCampusId(), onlineTest.getGradeId(), onlineTest.getSubjectId(), onlineTestResult.getScore());
        Student student = studentService.findById(onlineTest.getStudentId());
        List<Integer> levels = new ArrayList<>(measurements.size());
        for(Measurement measurement : measurements ){
            levels.add(measurement.getLevel());
        }
        OnlineTestResultVo onlineTestResultVo = new OnlineTestResultVo();
        onlineTestResultVo.setGradeId(onlineTest.getGradeId());
        onlineTestResultVo.setGradeName(onlineTest.getGradeName());
        onlineTestResultVo.setSubjectId(onlineTest.getSubjectId());
        onlineTestResultVo.setSubjectName(onlineTest.getSubjectName());
        onlineTestResultVo.setScore(onlineTestResult.getScore());
        onlineTestResultVo.setStudentId(student.getStudentId());
        onlineTestResultVo.setStudentName(student.getName());
        onlineTestResultVo.setLevels(levels);
        onlineTestResultVo.setIsPass(onlineTest.getIsPass());
        return ReturnResult.success(onlineTestResultVo) ;
    }


    @ApiOperation("获取课程讲次")
    @RequestMapping(value = "/classLectures" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ClassLecture>> classLectures(@RequestParam("classId") Long classId){
        List<ClassLecture> classLectures = classLectureService.findClassLectureByClassId(classId);
        return ReturnResult.success(classLectures) ;
    }

    @ApiOperation("获取可以调出班级")
    @RequestMapping(value = "/availableShiftOutCourseClasses" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<AvailableShiftOutCourseClassDto>> availableShiftOutCourseClasses(@RequestParam("studentId") Long studentId){

        StudentRegQueryVo studentRegQueryVo = new StudentRegQueryVo();
        studentRegQueryVo.setRegStatus(0);
        studentRegQueryVo.setChargingStatus(2);
        studentRegQueryVo.setStudentId(studentId);
        List<StudentReg> studentRegs = studentRegService.findStudentRegQuery(studentRegQueryVo);

        List<Long> classIds = BeanUtils.toList(studentRegs,"classId");

        List<CourseClass> courseClasses = courseClassService.findByIds(classIds, CourseClass.BASE_FIELDS);
        Map<Long,CourseClass> classId2CourseClassMap = BeanUtils.toMap(courseClasses,"classId");

        List<AvailableShiftOutCourseClassDto> availableShiftOutCourseClassDtos = new ArrayList<>(studentRegs.size());

        for(StudentReg studentReg : studentRegs ){
            CourseClass courseClass = classId2CourseClassMap.get(studentReg.getClassId());
            if(courseClass.getProgressStatus() == 2 || courseClass.getLectureAmount().intValue() == courseClass.getCompletedLectureAmount().intValue() ){
                continue;
            }
            availableShiftOutCourseClassDtos.add(new AvailableShiftOutCourseClassDto(studentReg,courseClass));
        }

        return ReturnResult.success(availableShiftOutCourseClassDtos) ;
    }

    @ApiOperation("判断班级是否可调")
    @RequestMapping(value = "/checkCanShift" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ClassLecture>> classLectures(@RequestParam("classId") long classId,@RequestParam("studentId")long studentId){
        shiftClassRecordService.checkCanShift(classId,studentId);
        return ReturnResult.success("ok") ;
    }


    @ApiOperation("获取可以调进班级")
    @RequestMapping(value = "/availableShiftInCourseClasses" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Collection<CourseClass>> availableShiftInCourseClasses(@RequestParam("shiftOutLectureNo") Integer shiftOutLectureNo ,@RequestParam("shiftOutClassId") Long shiftOutClassId , @RequestParam(value = "campusId" , required = false ) Long campusId ){

        CourseClass courseClass = courseClassService.findById(shiftOutClassId, CourseClass.BASE_FIELDS);
        CourseClassQueryVo courseClassQueryVo = new CourseClassQueryVo();
        if(campusId != null ){
            courseClassQueryVo.setCampusId(campusId);
        }
        courseClassQueryVo.setAreaTeamId(courseClass.getAreaTeamId());
        courseClassQueryVo.setGradeId(courseClass.getGradeId());
        courseClassQueryVo.setSubjectId(courseClass.getSubjectId());
        courseClassQueryVo.setLevel(courseClass.getLevel());
        courseClassQueryVo.setStatus(1);
        courseClassQueryVo.setPeriodId(courseClass.getPeriodId());
        courseClassQueryVo.setLectureAmount(courseClass.getLectureAmount());
        courseClassQueryVo.setProgressStatusList(Arrays.asList(0,1));
        Page<CourseClass> page = courseClassService.findCourseClassByQuery(courseClassQueryVo, 0, 1000);
        List<CourseClass> courseClasses = page.getRecords();
        return ReturnResult.success(Collections2.filter(courseClasses,(c)-> c.getCompletedLectureAmount() < shiftOutLectureNo && c.getCompletedLectureAmount() < c.getLectureAmount() && c.getLectureAmount() >= shiftOutLectureNo  )) ;
    }

    @ApiOperation("查询学生报读讲次")
    @RequestMapping(value = "/classLectureOfStudent", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ClassLectureWithAttendClassVo>> classLectureOfStudent(@RequestParam(value = "regId") Long regId ){

        StudentReg studentReg = studentRegService.findById(regId );
        List<ClassLecture> regClassLectureList = classLectureService.findRegClassLectureByRegId(studentReg);
        List<Long> classLectureIds = BeanUtils.toList(regClassLectureList,"classLectureId");
        List<AttendClassRecord> attendClassRecordList = attendClassRecordService.findByRegIdClassLectureIds(studentReg.getRegId(), classLectureIds);
        Map<Long,AttendClassRecord> classLectureId2AttendClassRecord = BeanUtils.toMap(attendClassRecordList,"classLectureId");
        List<ClassLectureWithAttendClassVo> classLectureWithAttendClassVos = new ArrayList<>(attendClassRecordList.size());
        for(ClassLecture classLecture : regClassLectureList ){
            ClassLectureWithAttendClassVo classLectureWithAttendClassVo = new ClassLectureWithAttendClassVo();
            BeanUtils.copyProperties(classLectureWithAttendClassVo,classLecture);
            classLectureWithAttendClassVo.setAttendClassRecord(classLectureId2AttendClassRecord.get(classLecture.getClassLectureId()));
            classLectureWithAttendClassVos.add(classLectureWithAttendClassVo);
        }

        return ReturnResult.success(classLectureWithAttendClassVos);
    }



    @ApiOperation("确认调课")
    @RequestMapping(value = "/confirmShiftClass" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ClassLecture>> confirmShiftClass(@RequestParam("shiftOutAttendClassRecordId") Long  shiftOutAttendClassRecordId ,@RequestParam("shiftInClassId") Long shiftInClassId , @RequestParam(value = "shiftLectureNo") Integer shiftLectureNo ){

        ClassLecture destClassLecture = classLectureService.findClassLectureByClassIdLectureNo(shiftInClassId, shiftLectureNo);
        AttendClassRecord fromAttendClassRecord = attendClassRecordService.findById(shiftOutAttendClassRecordId);
        shiftClassRecordService.saveShiftClass(fromAttendClassRecord,destClassLecture,"" , new Principals.Principal(0l,"线上"));
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("获取当前城市所有校区")
    @RequestMapping(value = "/campusOfCity" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Campus>> campusOfCity(@RequestParam("city") String city){
        List<Campus> campus = campusService.findCampusByCity(city);
        return ReturnResult.success(campus) ;
    }

    @ApiOperation("获取当前城市所有校区")
    @RequestMapping(value = "/campusOfAreaTeam" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,List<Campus>>> campusOfAreaTeam(@RequestParam("areaTeamId") long areaTeamId){
        List<Campus> campusList = campusService.findCampusByAreaTeamIdState(areaTeamId,1);
        Map<Object, List<Campus>> map = BeanUtils.toGroup(campusList, "district");
        return ReturnResult.success(map) ;
    }

    @ApiOperation("余额支付确认")
    @RequestMapping(value = "/confirmPayForOnlyBalance" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> confirmPayForOnlyBalance(@RequestParam("payOrderId") Long payOrderId){
        outerOrderService.confirmPayForOnlyBalance(payOrderId);
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("详情页推荐课程")
    @RequestMapping(value = "/suggestCourseClassForDetailPage" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<OuterCourseClass>> suggestCourseClassForDetailPage(@RequestParam("classId") Long classId){
        List<OuterCourseClass> outerCourseClasses = suggestionService.suggestCourseClassByClass(classId);
        return ReturnResult.success(outerCourseClasses) ;
    }

    @ApiOperation("获取校区详情")
    @RequestMapping(value = "/campusDetail" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OuterCampusVo> campusDetail(@RequestParam("campusId") Long campusId ,@RequestParam(value = "longitude" , required = false ) Double longitude,@RequestParam(value = "latitude",required = false ) Double latitude ){
        OuterCampus outerCampus = outerCampusService.findById(campusId);
        OuterCampusVo outerCampusVo = new OuterCampusVo() ;
        BeanUtils.copyProperties(outerCampusVo,outerCampus);
        if(longitude != null && latitude != null & outerCampus.getCampusLocation() != null ){
            outerCampusVo.setDistance(DistanceUtils.getDistance(latitude,longitude,outerCampus.getCampusLocation().getY(),outerCampus.getCampusLocation().getX() ));
        }else{
            outerCampusVo.setDistance(0);
        }
        return ReturnResult.success(outerCampusVo) ;
    }


    @ApiOperation("获取订单优惠说明")
    @RequestMapping(value = "/orderDiscountDesc" , method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Collection<OrderDiscountItemVo>> orderDiscountDesc(@RequestParam("outerOrderId") Long outerOrderId ){
        OuterOrder outerOrder = outerOrderService.findById(outerOrderId, "subOrderIds");
        List<CourseOrderDiscount> courseOrderDiscounts = courseOrderDiscountService.findByCourseOrderIds(Utils.toLongIds(outerOrder.getSubOrderIds()));
        Collection<OrderDiscountItemVo> orderDiscountItems = Collections2.transform(courseOrderDiscounts,this::toOrderDiscountItemVo);
        return ReturnResult.success(orderDiscountItems) ;
    }

    private OrderDiscountItemVo toOrderDiscountItemVo(CourseOrderDiscount courseOrderDiscount){
        OrderDiscountItemVo orderDiscountItemVo = new OrderDiscountItemVo() ;
        BeanUtils.copyProperties(orderDiscountItemVo,courseOrderDiscount);
        return orderDiscountItemVo;
    }

    @ApiOperation("添加订单优惠")
    @RequestMapping(value = "/addDiscount", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addDiscount(@RequestParam("outerOrderId") Long outerOrderId , @RequestParam("discountCode") String discountCode,@RequestParam("discountId") Long discountId) {
        outerOrderService.addDiscount(outerOrderId,discountCode,discountId);
        return ReturnResult.success("OK");
    }

    @ApiOperation("优惠码查询")
    @RequestMapping(value = "/queryDiscountCode", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<QueryDiscountCodeResult> queryDiscountCode(@RequestParam("outerOrderId") Long outerOrderId , @RequestParam("discountCode") String discountCode,@RequestParam("discountId") Long discountId) {
        QueryDiscountCodeResult discountCodeResult = discountService.queryDiscountCodeResult(outerOrderId, discountCode, discountId);
        return ReturnResult.success(discountCodeResult);
    }


    @ApiOperation("课程过滤条件配置")
    @RequestMapping(value = "/courseFilterCondConfig", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CourseFilterCondConfig> courseFilterCondConfig(@RequestParam("areaTeamId") Long areaTeamId ) {
        CourseFilterCondConfig courseFilterCondConfig = configService.findCourseFilterCondConfigFromCache(areaTeamId);

        if(courseFilterCondConfig != null ){
            for(CourseFilterCondConfig.Item item : courseFilterCondConfig.getPeriods() ){
                item.put("teachers" ,Collections.EMPTY_LIST );
            }
        }

        return ReturnResult.success(courseFilterCondConfig);
    }

    @ApiOperation("课程过滤条件配置(老师)")
    @RequestMapping(value = "/teacherOfCourseFilterCondConfig", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CourseFilterCondConfig.Item> > teacherOfCourseFilterCondConfig(@RequestParam("areaTeamId") Long areaTeamId ,@RequestParam(value = "periodId" , required = false ) String periodId ) {
        CourseFilterCondConfig courseFilterCondConfig = configService.findCourseFilterCondConfigFromCache(areaTeamId);

        List<CourseFilterCondConfig.Item> list = Collections.EMPTY_LIST ;
        if(courseFilterCondConfig != null ){
            for(CourseFilterCondConfig.Item item : courseFilterCondConfig.getPeriods() ){
                if(StringUtils.isNotEmpty(periodId)){
                    if(periodId.equals(item.get("value"))){
                        list = (List<CourseFilterCondConfig.Item>) item.get("teachers");
                        break;
                    }
                }else{

                    if(StringUtils.isEmpty((String)item.get("value"))){
                        list = (List<CourseFilterCondConfig.Item>) item.get("teachers");
                        break;
                    }
                }
            }
        }
        return ReturnResult.success(list);
    }

    @ApiOperation("获取广告")
    @RequestMapping(value = "/ad", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<AdConfig>> ad(@RequestParam("areaTeamId") Long areaTeamId,@RequestParam("page") String page,@RequestParam("position") String position) {
        List<AdConfig> ads = configService.findAdConfigByAreaTeamIdPagePosition(areaTeamId, page, position);
        return ReturnResult.success(ads);
    }

    @ApiOperation("余额充值")
    @RequestMapping(value = "/u/rechargeBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> rechargeBalance(HttpServletRequest request,@RequestParam("areaTeamId")long areaTeamId,@RequestParam("studentId") long studentId, @RequestParam("amount") BigDecimal amount) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        String userName=accessTokenVo.getName();
        AccountRecharge accountRecharge = accountRechargeService.prepareAccountRecharge(areaTeamId, IdWorker.getId(), studentId, null, null, amount, null, userId, userName);
        return ReturnResult.success(accountRecharge.getAccountRechargeId());
    }

    @ApiOperation("学生余额")
    @RequestMapping(value = "/u/studentBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> studentBalance(HttpServletRequest request,@RequestParam("studentId") long studentId) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        MainAccount mainAccount=mainAccountService.findById(studentId);
        return ReturnResult.success(mainAccount);
    }


    @ApiOperation("获取可以转入的班级")
    @RequestMapping(value = "/u/canChangeClassList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CourseClass>> canChangeClassList(@ApiParam("转出的班级id")@RequestParam("classId")long classId,@ApiParam("起始讲次")@RequestParam("startLectureNo") int startLectureNo ,@ApiParam("结束讲次")@RequestParam("endLecureNo") int endLecureNo ,@RequestParam(value = "campusId",required = false)Long campusId,@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize) {

        CourseClass courseClass=courseClassService.findById(classId);

        CourseClassQueryVo courseClassQueryVo=new CourseClassQueryVo();
        courseClassQueryVo.setCampusId(campusId);
        courseClassQueryVo.setAreaTeamId(courseClass.getAreaTeamId());
        courseClassQueryVo.setStudyingFee(courseClass.getStudyingFee());
        courseClassQueryVo.setGradeId(courseClass.getGradeId());
        courseClassQueryVo.setSubjectId(courseClass.getSubjectId());
        courseClassQueryVo.setLevel(courseClass.getLevel());
        courseClassQueryVo.setPeriodId(courseClass.getPeriodId());
        courseClassQueryVo.setProgressStatusList(Arrays.asList(0,1));
        Page<CourseClass> courseClassPage=courseClassService.findCanChangeClassPage(courseClass.getClassId(),courseClassQueryVo,startLectureNo,endLecureNo,pageNo,pageSize);

        return ReturnResult.success(courseClassPage);
    }

    @ApiOperation("确定转班")
    @RequestMapping(value = "/u/turnClass", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> turnClass(@ApiParam("原先报名信息id")@RequestParam("regId") Long regId  ,
                                        @ApiParam("转入的班级id")@RequestParam("classId") Long classId,
                                        @RequestParam("startLectureNo") int startLectureNo ,
                                        @RequestParam("endLectureNo") int endLectureNo,
                                        @RequestParam(value = "reason",required = false ) String reason){
        StudentReg studentReg=studentRegService.findById(regId);
        ClassExpandDetail classExpandDetail = classExpandDetailService.findById(studentReg.getClassId());
        if (classExpandDetail!=null && classExpandDetail.getChangeState()!=null &&  classExpandDetail.getChangeState()==0){
            throw new BusException("该班级不允许线上转班，如需转班，请直接咨询校区，谢谢！");
        }
        Principals.Principal principal = new Principals.Principal(0L, "线上");
        studentRegService.changeClass(regId,startLectureNo,classId,startLectureNo,endLectureNo,reason,principal );
        return ReturnResult.success("ok");
    }


    @ApiOperation("确定转班")
    @RequestMapping(value = "/u/canChange", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> canChange(@ApiParam("转出的班级id")@RequestParam("classId") Long classId){

        ClassExpandDetail classExpandDetail = classExpandDetailService.findById(classId);
        if (classExpandDetail!=null &&  classExpandDetail.getChangeState()!=null && classExpandDetail.getChangeState()==0){
            throw new BusException("该班级不允许线上转班，如需转班，请直接咨询校区，谢谢！");
        }
        return ReturnResult.success("ok");
    }






    @ApiOperation("学位预约")
    @RequestMapping(value = "/u/degreeSubscribe", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> degreeSubscribe(HttpServletRequest request,@RequestParam("classId")long classId,@RequestParam(value = "remark",required = false) String remark, @RequestParam(value = "phoneNo",required = false) String phoneNo,@RequestParam(value = "code",required = false)String code) {
        AccessTokenVo accessTokenVo=(AccessTokenVo)request.getAttribute("accessToken");
        Long userId=accessTokenVo.getUserId();
        DegreeSubscribeSaveVo degreeSubscribeSaveVo=new DegreeSubscribeSaveVo();
        degreeSubscribeSaveVo.setClassId(classId);
        degreeSubscribeSaveVo.setCustomerUserId(userId);
        degreeSubscribeSaveVo.setRemark(remark);
        if (StringUtils.isNotEmpty(phoneNo)){
            if( !smsService.validate(phoneNo, code) ){
                throw new BusException("手机验证码不正确");
            }
            degreeSubscribeSaveVo.setPhoneNo(phoneNo);
        }else {

            CustomerUser customerUser=customerUserService.findById(userId);
            degreeSubscribeSaveVo.setPhoneNo(customerUser.getPhoneNo());
        }
        degreeSubscribeService.saveDegreeSubscribe(degreeSubscribeSaveVo);
        return ReturnResult.success("ok");
    }


    @ApiOperation("我的课程听课证")
    @RequestMapping(value = "/u/courseRegistrationCard", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map> courseRegistrationCard(HttpServletRequest request,@RequestParam("regId")long regId) {
        StudentReg studentReg=studentRegService.findById(regId);
        Student student=studentService.findById(studentReg.getStudentId());
        OuterCourseClass courseClass = outerCourseClassService.findByClassId(studentReg.getClassId());
        Campus campus= campusService.findById(courseClass.getCampusId());
        Map<String,Object> map = new HashMap<>();
        map.put("studentReg",studentReg);
        map.put("student",student);
        map.put("courseClass",courseClass);
        map.put("campus",campus);
        return ReturnResult.success(map);
    }

    @ApiOperation("刷新未支付订单使用的余额")
    @RequestMapping(value = "/u/refreshOuterOrderBalancePays", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> refreshOuterOrderBalancePays(@ApiParam("订单id")@RequestParam("outerOrderId") long outerOrderId){
        outerOrderService.refreshOuterOrderBalancePays(outerOrderId);
        return ReturnResult.success("ok");
    }


    @ApiOperation("检查课程是否可报名")
    @RequestMapping(value = "/checkRegAvailable", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<Long, IRegRuleService.Result>> checkRegAvailable(@ApiParam("学生id")@RequestParam("studentId") Long studentId , @ApiParam("classIds") @RequestParam("classIds[]") List<Long> classIds){
        Map<Long, IRegRuleService.Result> resultMap = regRuleService.regRule(studentService.findById(studentId), courseClassService.findByIds(classIds), 1);
        return ReturnResult.success(resultMap);
    }





}
